/**
 * @filename HuJiaoShare
 *
 * @module
 *
 * @author Justin <zhou78620051@126.com>
 * @version 1
 * @time 2015/10/18 21:19
 */

var Logger = require('pomelo-logger').getLogger('HuJiao', 'production');

module.exports = {
  "loadData": function (req, res) {
    var msg_id = req.query.msg_id;
    var pageinfo;
    HuJiaoShare.findOne(msg_id, function (err, shares) {
      Logger.info("Load Share Data", msg_id, err, shares);
      if (err || !shares) {
        return res.json({});
      }

      pageinfo = shares;
      HuJiaoComments.find({"msg_id": msg_id}, function (err, comments) {
        Logger.info("Load Comments Data", msg_id, err, comments);
        if (err || !comments || !(comments instanceof Array)) {
          comments = [];
        }
        pageinfo.comment_list = comments;
        res.json(pageinfo);
      });
    });
  }
};
